class @AdminAuthorEditView extends CustomView
    
    el: $('#content')

    initialize: ->
        super
        @model.bind("change", @render)
        @model.fetch()

    render: ->
        @GetTemplate(SiteMap.Admin.Authors.EditTemplate, (compiledTemplate) =>
            $(@el).html(compiledTemplate(@model.toJSON()))
        )

    events: 
        "click .buttons>button.save": "save"
        "click .buttons>button.cancel": "cancel"

    save: (e) ->
        e.preventDefault()
        Loading.Start()
        Messages.WriteMessage('Saving author.')

        data = @$el.find("form.general").serialize()
            
        $.post(@model.url(), data, (response) =>
            if (response.SuccessMessage? && response.SuccessMessage.length)
                Messages.WriteSuccessMessage(response.SuccessMessage)
                @Navigate(SiteMap.Admin.Authors.Listing, true)
            else
                Messages.WriteErrors(response.Errors)
                Loading.Stop()
        )

    cancel: (e) ->
        e.preventDefault()
        Loading.Start()
        Messages.Clear()
        @Navigate(SiteMap.Admin.Authors.Listing, true)
